package edu.nf.util.audio;

import javazoom.jl.decoder.JavaLayerException;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javazoom.jl.player.Player;

/**
 * @Date 2023-06-21
 * @Author qiu
 * 播放音频的工具类
 * 当商家接到订单就调用此类的方法
 * 就会响起对应的音频
 */
public class AudioUtil {

    // 调用本地音频
    public static void play() throws FileNotFoundException, JavaLayerException {
        // 指定路径，读取本地的音频
        File file = new File("D:\\学期项目\\外卖提示音\\新的订单查收.mp3");

        // 读取音频的数据流
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream stream = new BufferedInputStream(fis);

        // 把数据流传递给 player 对象
        Player player = new Player(stream);
        player.play();
    }

    public static void main(String[] args) throws FileNotFoundException, JavaLayerException {
        play();
    }

}
